<?php

class BlogController extends Controller_Site 
{
	private $blogRow;
	
	public function preDispatch()
	{
		$id = $this->_getParam('id');
		if ($id) {
			$blogRow = $this->getBlogService()->getBlogById($id);
			if (!$blogRow) {
				// redirect to 404
			}
			$this->blogRow = $blogRow;
		}
	}
	
	public function indexAction()
	{
		$this->view->blog = ContentListElement::fromRow($this->blogRow);
		// get posts
		$postRowset = $this->getBlogService()->getPosts($this->blogRow, 10, 1);
		$this->view->posts = ContentList::fromRowset($postRowset);
	}
	
	public function listAction()
	{
		$tagRowset = $this->getTagService()->getAllTags();
		$this->view->tags = $tagRowset->toArray();
		
		// get list of popular blogs
		$rowset = $this->getBlogService()->getLastBlogs(25);
		$this->view->lastBlogs = ContentList::fromRowset($rowset);
	}
	
	public function secondListAction()
	{
		$tagRowset = $this->getTagService()->getAllTags();
		$this->view->tags = $tagRowset->toArray();
		
		$rowset = $this->getBlogService()->getBlogsByMostSubscribers(25);
		$this->view->lastBlogs = ContentList::fromRowset($rowset);
	}
	
	
}